//
//  UIAlertController+Block.m
//  高仿暴走斗图
//
//  Created by key on 16/3/23.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "UIAlertController+Block.h"

@implementation UIAlertController (Block)

+ (void)showAlertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle showViewController:(UIViewController *)viewController alertActions:(NSArray<UIAlertAction *> *)alertActions presentCompletion:(void(^)())completion {
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:preferredStyle];
    for (UIAlertAction *action in alertActions) {
        [alertController addAction:action];
    }
    [viewController presentViewController:alertController animated:YES completion:^{
        completion();
    }];
}

+ (UIAlertAction *)createActionForTitle:(NSString *)title style:(UIAlertActionStyle)style isEnabled:(BOOL)enabled actionHandler:(void(^)(UIAlertAction *action))handler {
    
    UIAlertAction *alertAction = [UIAlertAction actionWithTitle:title style:style handler:^(UIAlertAction * _Nonnull action) {
        if (handler) {
            handler(action);
        }
    }];
    alertAction.enabled = enabled;
    
    return alertAction;
}

+ (UIAlertAction *)createActionForTitle:(NSString *)title style:(UIAlertActionStyle)style actionHandler:(void(^)(UIAlertAction *action))handler {
    
    return [UIAlertController createActionForTitle:title style:style isEnabled:YES actionHandler:^(UIAlertAction *action) {
        if (handler) {
            handler(action);
        }
    }];
}

@end
